﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace MLM.Base
{
    public partial class BasePage : Page
    {
        private static string DefaultCulture = "de-DE";        
        protected override void InitializeCulture()
        {
            //Culture
            try
            {
                string selectedLanguage = DefaultCulture;
                if (Request.QueryString["MLMCulture"] != null)
                {
                    selectedLanguage = Request.QueryString["MLMCulture"];
                }
                else if (Session["MLMCulture"] != null)
                {
                    selectedLanguage = Session["MLMCulture"].ToString();
                }
                else
                {
                    selectedLanguage = DefaultCulture;
                }
                Page.UICulture = selectedLanguage;
                Page.Culture = selectedLanguage;
                Thread.CurrentThread.CurrentCulture =
                    CultureInfo.CreateSpecificCulture(selectedLanguage);
                Thread.CurrentThread.CurrentUICulture = new
                    CultureInfo(selectedLanguage);               
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.Message);               
            }            
            // Base
            base.InitializeCulture();
        }
        public static void ResetCultureToDefault(Page page)
        {
            page.UICulture = DefaultCulture;
            page.Culture = DefaultCulture;
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture(DefaultCulture);
            Thread.CurrentThread.CurrentUICulture = new
                CultureInfo(DefaultCulture);
        }
        protected override void OnInit(EventArgs e)
        {            
            base.OnInit(e);
        }        
    }
}
